/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* deleteNode(ListNode* head, int val) {
        if(head->val == val)return head->next;
        ListNode *pre = head, *temp = head->next;
        while(temp){
            if(temp->val == val){
                pre->next = temp->next;
                return head;
            }
            temp = temp->next;
            pre = pre->next;
        }
        return head;
    }
};

//2021.4.13
